package contextManager

import scala.actors._
import scala.tools.nsc.Interpreter
import scala.tools.nsc.Interpreter._
import messages._
import server.Content
import server.Server

abstract class Adaptable extends Actor{	
	implicit val server:Adaptable = this	
	private   val interpreter = new Interpreter()
	
	protected def setup():Unit = {
		interpreter.interpret("import server.implicits._")
	}
	
	def act(){
		while(true){
			receive {
				case Implementation(methodName, function) => {
					println("ADAPTABLE-SERVER: Updating method "+methodName)
					Adaptable.temporaryFunction = function
					interpreter.interpret(this.getClass().getName().dropRight(1)+"."+methodName+
							"=contextManager.Adaptable.temporaryFunction")
					println("DONE")

				}
				case Stop => return
			}
		}
	}
}

object Adaptable{
	var temporaryFunction:(Nothing)=>Any = null
}